<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>手工护理提成设定模板管理</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		fieldset{
			width:100%;
		}
		.ui-field-contain fieldset div.ui-input-text{
			float:left;
			width:60%;
		}
		#careList{
			float:right;width:78%;height:300px;border:1px solid #cccccc;display:block;
			overflow: auto;border-radius:0;
		}
		#careList li a{
			border-color:#f3f3f3;
			background:#fff;
			color:#000;
		}
	</style>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#name").focus();
			$("#inputForm").validate({
				rules:{
	                "fixed_money": "ifMoney",
	                "bonus_rate": {
	                 	"range":[0,100] 
	                 }
	            },
				submitHandler: function(form){
					var ids = "";
					var lists = $("#careList li");
					for(var i =0; i < lists.length; i++) {
						var item = lists[i];
						ids += item.id + ",";
					}
					if(ids == ''){
						showTip("没有选择会员卡！");
						return;
				 	}
					$("#careIds").val(ids);
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			var type = '${type}';
			if(type != "1") {
				var bonus_type = ${storeBonusSettingTemplateCare.bonus_type};
				if(bonus_type == 0) {
					$("#type_radio_2").css('display', 'none');
		     		$("#type_radio_1").css('display', 'block');
				} else {
					$("#type_radio_1").css('display', 'none');
		     		$("#type_radio_2").css('display', 'block');
				}
	     		$('input:radio').click(function(){
	             	var id =  $(this).val();
	             	if(id == 0) {
	             		$("#bonus_rate").val('0');
	             		$("#fixed_money").val('0.0');
	             		$("#type_radio_2").css('display', 'none');
	             		$("#type_radio_1").css('display', 'block');
	             		
	             	} else {
	             		$("#bonus_rate").val('0');
	             		$("#fixed_money").val('0.0');
	             		$("#type_radio_1").css('display', 'none');
	             		$("#type_radio_2").css('display', 'block');
	             	}
	            });
			}
		});
		function addCare(url, obj){
			var type = '${type}';
			var title = $(obj).val();
			var extIds = "";
			var lists = $("#careList li");
			for(var i =0; i < lists.length; i++) {
				var item = lists[i];
				extIds += item.id + ",";
			}
			global.addMultSelectList(url, title, extIds, "careList");
		}
	</script>
</head>
<body>
	<form:form id="inputForm" class="form-input" modelAttribute="storeBonusSettingTemplateCare" action="${ctx}/employee/storeBonusSettingTemplateCare/addList" method="post">
		<form:hidden path="id"/>
		<input id="careIds" name="careIds" type="hidden"/>
		<input id="type" name="type" value="${type}" type="hidden"/>
		<div class="icon-buttons">
			<a data-role="button" data-inline="true" data-icon="back" data-iconpos="notext"  href="${ctx}/employee/storeBonusSettingTemplateCare/list?type=${type}">返回</a>
			<input type="submit" value="保 存" data-icon="check" data-iconpos="notext"  data-inline="true"/>
		</div>
		<tags:message content="${message}"/>
		<div data-role="fieldcontain">
			<c:if test="${type == 0}">
				<label for="careList">选择计次护理卡:</label>
				<input type="button" value="选择计次护理卡" data-inline="true" data-icon="plus" onclick="addCare('${ctx}/employee/storeBonusSettingTemplateCare/timesCardTemplateData', this)">
			</c:if>
			<c:if test="${type == 1}">
				<label for="careList">选择时段护理卡:</label>
				<input type="button" value="选择时段护理卡" data-inline="true" data-icon="plus" onclick="addCare('${ctx}/employee/storeBonusSettingTemplateCare/durationCardTemplateData', this)">
			</c:if>
			<c:if test="${type == 2}">
				<label for="careList">护理项目:</label>
				<div>
					<input type="button" value="系统护理项目" data-inline="true" data-icon="plus" onclick="addCare('${ctx}/employee/storeBonusSettingTemplateCare/allCardTemplateData?type=0', this)">
					<input type="button" value="店面护理项目" data-inline="true" data-icon="plus" onclick="addCare('${ctx}/employee/storeBonusSettingTemplateCare/allCardTemplateData?type=1', this)">
				</div>
			</c:if>
			<c:if test="${type == 3}">
				<label for="careList">护理项目:</label>
				<div>
					<input type="button" value="系统护理项目" data-inline="true" data-icon="plus" onclick="addCare('${ctx}/employee/storeBonusSettingTemplateCare/moneyCardTemplateData?type=0', this)">
					<input type="button" value="店面护理项目" data-inline="true" data-icon="plus" onclick="addCare('${ctx}/employee/storeBonusSettingTemplateCare/moneyCardTemplateData?type=1', this)">
				</div>
			</c:if>
			<ul id="careList" data-role="listview" data-inset="true"  data-split-icon="delete" data-split-theme="a">
			</ul>
		</div>
		<div data-role="fieldcontain">
			<c:if test="${type == 0 || type == 2 || type == 3}">
				<fieldset data-role="controlgroup" data-type="horizontal" data-inline="true">
					<legend>提成方式:</legend>
					<form:radiobuttons path="bonus_type" items="${fns:getDictMap('bonus_type')}"/>
				</fieldset>
			</c:if>
			<c:if test="${type == 1}">
				<input type="hidden" name="bonus_type" value="1"/>
				<fieldset data-role="controlgroup" data-type="horizontal" data-inline="true">
					<legend>提成方式:</legend>按固定金额提成
				</fieldset>
			</c:if>
		</div>
		<c:if test="${type == 0 || type == 2 || type == 3}">
			<div data-role="fieldcontain" id="type_radio_1">
	   			<label for="bonus_rate">提成比例(%):</label>
	    		<input type="number" id="bonus_rate" value="${fns:changeDisCount(storeBonusSettingTemplateCare.bonus_rate)}" name="bonus_rate" class="required digits"/>
			</div>
		</c:if>
		<div data-role="fieldcontain" id="type_radio_2">
			<label for="fixed_money">提成金额(元):</label>
			<form:input path="fixed_money" htmlEscape="false" class="required"/>
		</div>
	</form:form>
</body>
</html>
